/*
 * UVic SENG 265, Fall 2011, A#4
 * Author: Lee D Gauthier
 * ID: V00681729
 *  
 */

#include <stdio.h>
#include <stdlib.h>
#include "uvic_formatter.h"
#include <string.h>

int main(int argc, char *argv[]) {
    /*Initialize those Variables*/
    FILE *fp = NULL;
    fp = fopen(argv[1],"r");
    char **result = NULL;
    char **line = NULL;
    
    /*Based on the args decides to use File In or Std In*/
    if(argc == 2){
        result = format_file(fp);
    }else if (argc == 1){
        result = format_file(stdin);
    }else{
        fprintf(stderr, "Wrong args\n");
        exit(1);
    }

	if (result == NULL) {
		printf("%s: it appears 'format_lines' is not yet complete\n",
			argv[0]);
		exit(1);
	}
    
    /*checks if *result is alread NULL*/
	if (*result == NULL) {
		exit(1);
	}
    
    /*Prints the resulting lines*/
	for (line = result; *line != NULL; line++) {
		printf ("%s\n", *line);
	}
    
    /*Close that file if it was opened*/
    if(fp != NULL){fclose(fp);}
	return 0;
}
